#include <iostream>
#include<vector> 
#include <string>
using namespace std;

int main() {
    vector<int> v1 = {2,5,20};
    int n = 0, cost;
    cin >> n;
    v1.reserve(n);
    //while (n--)
    //{
    //    cin >> cost;
    //    v1.push_back(cost);
    //}
    int sum1 = 0, sum2 = 0;
    for (int i = 1; i < n;)
    {
        if (v1[i-1] > v1[i])
        {
            sum1 += v1[i-1];
            continue;
        }
        else sum1 += v1[i];
        ++i;
    }

    for (int i = 2; i < n;)
    {
        if (v1[i] > v1[i -1])
        {
            sum2 += v1[i-1];
            continue;
        }
        else sum2 += v1[i];
        ++i;
    }
    printf("%d", sum1 > sum2 ? sum2 : sum1);
    return 0;
}
int main() {
    int n = 0, min = -1, s1 = -1, s2 = -1, i = 0;
    string strs, str1, str2;
    //vector<string> v;
    cin >> n;
    cin >> str1 >> str2;
    while (n--)
    {
        cin >> strs;
        if (strs == str1)
        {                   
            if (s1 == -1 || (size_t)min > abs(s2 - i))
                s1 = i;
            if (s2 != -1)
                min = abs(s2 - s1);
        }
        if (strs == str2)
        {
            if (s2 == -1 || (size_t)min > abs(i - s1))
                s2 = i;
            if (s1 != -1)
                min = abs(s2 - s1);
        }
        //v.push_back(strs);
        i++;
    }
    //if (s1 == -1 || s2 == -1) printf("%d", min);
    //printf("%d", s2 - s1);
    printf("%d", min);
    return 0;
}

//5
//QWER 666
//QWER
//1234
//qwe
//666
//QWER